<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { KeyValues } from '../../utils/types';
import { apiAuth } from '../../api';


const props = defineProps<{
  row?: any
}>()

const emit = defineEmits(['close', 'submitted'])

const form = ref<KeyValues>({})

const close = () => emit('close')

const onOk = async () => {
  emit('submitted', { form: form.value })
}
const sysParams = ref<KeyValues[]>()
onMounted(() => {
  if (props.row) {
    form.value = { ...props.row }
  }
  apiAuth.getSysParam( props.row.apiAuthId ).then(res => {
    sysParams.value = res.data
  })
})
</script>

<template>
  <ElDialog ref="dialogRef" title="系统变量配置">
    <ElForm ref="formRef" label-width="6em" :model="form">
      <ElFormItem label="系统参数" prop="sourceValue">
        <ElSelect v-model ="form.sourceValue">
          <ElOption v-for="_ in sysParams" :key="_.value" :value="_.code" :label="_.id" />
        </ElSelect>
      </ElFormItem>
    </ElForm>
    <template #footer>
      <ElButton @click="close">取消</ElButton>
      <ElButton type="primary" @click="onOk">确定</ElButton>
    </template>
  </ElDialog>
</template>

